/*自定义--校区管理-学校管理*/
import { routerRedux } from 'dva/router';
import * as LoginService from '../services/basics';

export default {
  namespace: 'campuschool',
  state: {
    data: [],
  },
  effects: {
  	/*学校管理*/
    *fetch_school({ payload }, { call, put }) {
      	const response = yield call(LoginService.get,'/api/web/school/slicedQuerySchool',payload); 
    	yield put({type: 'save',payload: response.data.obj,});
    },
    /*机构管理*/
    *fetch_organ_tree({ payload, callback }, { call, put }) {
      	const response = yield call(LoginService.get,'/api/web/org/getOrgTreeList');
    	callback(response.data.res,response.data.obj);
    },
    /*新增学校*/
    *add_school({ payload, callback }, { call, put }) {
      	const response = yield call(LoginService.get,'/api/web/school/insertSchool', payload);
      	callback(response.data.res,response.data.resMsg);
     	yield put({type:'fetch_school',});
    },
    /*编辑学校*/
    *edit_school({ payload, callback }, { call, put }) {
      	const response = yield call(LoginService.get,'/api/web/school/updateSchool', payload);
     	callback(response.data.res,response.data.resMsg);
     	yield put({type:'fetch_school',});
     },
     /*修改状态*/
    *edit_school_state({ payload, callback }, { call, put }) {
      	const response = yield call(LoginService.get,'/api/web/school/updateSchoolStates', payload);
     	callback(response.data.res,response.data.resMsg);
     	yield put({type:'fetch_school',});
     },
     /*删除学校*/
    *remove_school({ payload, callback }, { call, put }) {
      	const response = yield call(LoginService.get,'/api/web/school/deleteSchools', payload);
      	callback(response.data.res,response.data.resMsg);
      	yield put({type:'fetch_school',});
    },
  },
  reducers: {
    save(state, action) {
      return {
        ...state,
        data: action.payload,
      };
    },
  },
};
